package com.ruoyi.user.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.CommonUtil;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.user.domain.UserThirdParty;
import com.ruoyi.user.mapper.UserThirdPartyMapper;
import com.ruoyi.user.service.IUserThirdPartyService;

/**
 * 用户第三方Service业务层处理
 * 
 * @author DEREK
 * @date 2023-05-10
 */
@Service
public class UserThirdPartyServiceImpl extends ServiceImpl<UserThirdPartyMapper, UserThirdParty> implements IUserThirdPartyService 
{
    @Autowired
    private UserThirdPartyMapper userThirdPartyMapper;

    /**
     * 查询用户第三方
     * 
     * @param id 用户第三方主键
     * @return 用户第三方
     */
    @Override
    public UserThirdParty selectUserThirdPartyById(Long id)
    {
        return userThirdPartyMapper.selectUserThirdPartyById(id);
    }

    /**
     * 查询用户第三方列表
     * 
     * @param userThirdParty 用户第三方
     * @return 用户第三方
     */
    @Override
    public List<UserThirdParty> selectUserThirdPartyList(UserThirdParty userThirdParty)
    {
        return userThirdPartyMapper.selectUserThirdPartyList(userThirdParty);
    }

    /**
     * 新增用户第三方
     * 
     * @param userThirdParty 用户第三方
     * @return 结果
     */
    @Override
    public int insertUserThirdParty(UserThirdParty userThirdParty)
    {
        userThirdParty.setCreateTime(DateUtils.getNowDate());
        return userThirdPartyMapper.insertUserThirdParty(userThirdParty);
    }

    /**
     * 修改用户第三方
     * 
     * @param userThirdParty 用户第三方
     * @return 结果
     */
    @Override
    public int updateUserThirdParty(UserThirdParty userThirdParty)
    {
        userThirdParty.setUpdateTime(DateUtils.getNowDate());
        return userThirdPartyMapper.updateUserThirdParty(userThirdParty);
    }

    /**
     * 批量删除用户第三方
     * 
     * @param ids 需要删除的用户第三方主键
     * @return 结果
     */
    @Override
    public int deleteUserThirdPartyByIds(Long[] ids)
    {
        return userThirdPartyMapper.deleteUserThirdPartyByIds(ids);
    }

    /**
     * 删除用户第三方信息
     * 
     * @param id 用户第三方主键
     * @return 结果
     */
    @Override
    public int deleteUserThirdPartyById(Long id)
    {
        return userThirdPartyMapper.deleteUserThirdPartyById(id);
    }
    
    @Override
	public UserThirdParty getInfoByUnionId(String unionId) {
		LambdaQueryWrapper<UserThirdParty> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(UserThirdParty::getUnionId,unionId);
		return this.baseMapper.selectOne(queryWrapper);
	}
    
    @Override
	public UserThirdParty getByAppleId(String appleId) {
    	LambdaQueryWrapper<UserThirdParty> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(UserThirdParty::getAppleId,appleId);
		return this.baseMapper.selectOne(queryWrapper);
	}
    
    @Override
	public boolean isBindMobile(String mobile,String relevantId) {
		Long bindMobile = this.baseMapper.isBindMobile(mobile,relevantId);
		if(CommonUtil.isEmpty(bindMobile)){
			return false;
		}
		if(bindMobile == 0) {
			return false;
		}
		return true;
	}
}
